package test4_2.demo03;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class Homework19_6 {
    public static void main(String[] args) {

        List<Student> list = new ArrayList();
        list.add(new Student("Tom", 18, 100, "class05"));
        list.add(new Student("Jerry", 22, 70, "class04"));
        list.add(new Student("Owen", 25, 90, "class05"));
        list.add(new Student("Jim", 30, 80, "class05"));
        list.add(new Student("Steve", 28, 66, "class06"));
        list.add(new Student("Kevin", 24, 100, "class04"));

        //1） 计算所有学生的平均年龄
        int age = 0;
        for (Student a : list) {
            age = age + a.getAge();
        }
        double averageAge = (double) age / list.size();
        System.out.println("平均年龄为：" + averageAge);

        //2） 计算各个班级的平均分
        /*
        class05:3个学生，总分：，平均分：
        class04:3个学生，总分：，平均分：
        class06:3个学生，总分：，平均分：
         */
        int stuCount1 = 0,stuCount2 = 0,stuCount3 = 0;
        double scoreSum1 = 0,scoreSum2 = 0,scoreSum3 = 0;
        for (Student s : list) {
            if (s.getClassNum().equals("class04")){
                stuCount1++;
                scoreSum1 += s.getScore();
            }else if (s.getClassNum().equals("class05")){
                stuCount2++;
                scoreSum2 += s.getScore();
            }else if (s.getClassNum().equals("class06")){
                stuCount3++;
                scoreSum3 += s.getScore();
            }
        }
        System.out.println("class03:"+stuCount1+"个学生，总分："+scoreSum1+"，平均分："+scoreSum1/(double)stuCount1);
        System.out.println("class04:"+stuCount2+"个学生，总分："+scoreSum2+"，平均分："+scoreSum2/(double)stuCount2);
        System.out.println("class05:"+stuCount3+"个学生，总分："+scoreSum3+"，平均分："+scoreSum3/(double)stuCount3);

    }
}
